<?
define('_VIEW_MODEL_','default');
require_once './init.php';
header("Content-type:text/vnd.wap.wml;charset=utf-8");
$id = intval($id);
if(isset($nid)){
	$nid = intval($nid);
}else{
	$nid = "";
}	
$nosty = array();
$key   = 0;
$info  = "";
if(isset($act)&&$act=="add"){
	$acthor = $db->GetRow("select * from {$telper}novel_author where userid=$id");
	$time  = time();
	//echo "insert into {$telper}novel set `title`='$bookname',`authid`='$id',`author`='$acthor[author]',`novelstyle`='$type',`creattime`='$time',`summary`='$bookinfo'";exit;
	$db->Execute("insert into {$telper}novel set `title`='$bookname',`authid`='$id',`author`='$acthor[author]',`novelstyle`='$type',`creattime`='$time',`summary`='$bookinfo'");
	header("Location:authorpage.php?id=$id&auid=$acthor[id]");
	exit;
}
if(isset($act)&&$act=="upnovel"){
	$acthor = $db->GetRow("select `id`,`author`,`userid` from {$telper}novel_author as a join left {$telper}novel as b on a.userid = b.authid where b.id=$nid");
	//echo "update {$telper}novel set `title`='$bookname',`novelstyle`='$type',`summary`='$bookinfo' where id = $id";exit;
	$db->Execute("update {$telper}novel set `title`='$bookname',`novelstyle`='$type',`summary`='$bookinfo' where id = $nid");
	header("Location:authorpage.php?id=$id&auid=$acthor[id]");
	exit;
}
$action = "add";
if(isset($ac)&&$ac=="edit"){
	//echo $nid;
	//echo "select `title`,`novelstyle`,`summary`,`authid` where id = $nid";
	$info = $db->GetRow("select `title`,`novelstyle`,`summary`,`authid` from {$telper}novel where id = $nid");
	$key  = $info['novelstyle'];
	$action = "upnovel";
}
foreach ($novelstyle as $k=>$v){
	$sel = $k==$key?'selected="selected"':"";
	$nosty[] = "<option value='$k' $sel >$v</option>";
}
$smartyObj->assign("nosty",$nosty);
$smartyObj->assign("acid",$nid);
$smartyObj->assign("uid",$id);

$smartyObj->assign("ace",$action);
$smartyObj->assign("info",$info);
$smartyObj->display("addnovel.tpl");
?>